import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询员工违规分析
 */
export async function pageEtpEmployeeViolationAnalysiss(params) {
  const res = await request.get('/etp/etpEmployeeViolationAnalysis/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部员工违规分析
 */
export async function listEtpEmployeeViolationAnalysiss(params) {
  const res = await request.get('/etp/etpEmployeeViolationAnalysis/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询员工违规分析
 */
export async function getEtpEmployeeViolationAnalysis(id) {
  const res = await request.get('/etp/etpEmployeeViolationAnalysis/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加员工违规分析
 */
export async function addEtpEmployeeViolationAnalysis(data) {
  const res = await request.post('/etp/etpEmployeeViolationAnalysis', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改员工违规分析
 */
export async function updateEtpEmployeeViolationAnalysis(data) {
  const res = await request.put('/etp/etpEmployeeViolationAnalysis', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除员工违规分析
 */
export async function removeEtpEmployeeViolationAnalysis(id) {
  const res = await request.delete('/etp/etpEmployeeViolationAnalysis/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除员工违规分析
 */
export async function removeEtpEmployeeViolationAnalysiss(ids) {
  const res = await request.delete('/etp/etpEmployeeViolationAnalysis/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出员工违规分析
 */
export async function exportEtpEmployeeViolationAnalysiss(params) {
  const res = await request({
    url: '/etp/etpEmployeeViolationAnalysis/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `etpEmployeeViolationAnalysis_${Date.now()}.xlsx`);
}
